package br.com.mmm.javacenter.framework.view.taglib.tags;

import java.io.IOException;
import java.io.Writer;
import java.util.Calendar;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import br.com.mmm.javacenter.framework.view.ContextAttributes;

public class JavaCenterSimpleTagSupport extends SimpleTagSupport{
	public void writeBody(Writer writer) throws JspException, IOException{
		if(getJspBody()!= null){
			getJspBody().invoke(writer);
		}
	}
	public String getAtributo(String nome,Calendar value){
		return getAtributo(nome, String.valueOf(value));
	}
	public String getAtributo(String nome,boolean value){
		return getAtributo(nome, String.valueOf(value));
	}
	public String getAtributo(String nome,long value){
		return getAtributo(nome, String.valueOf(value));
	}
	public String getAtributo(String nome,int value){
		return getAtributo(nome, String.valueOf(value));
	}
	public String getAtributo(String nome,Object value){
		return getAtributo(nome, value==null?null:String.valueOf(value));
	}
	public String getAtributo(String nome,String value){
		return (value!=null?nome+"=\""+value+"\"":"")+' ';
	}
	public void setRequestAttribute(String att,Object o){
		getJspContext().setAttribute(att,o,PageContext.REQUEST_SCOPE);
	}
	public Object getAttribute(String att){
		return getJspContext().getAttribute(att);
	}
	public Object getRequestAttribute(String att){
		return getJspContext().getAttribute(att,PageContext.REQUEST_SCOPE);
	}
	public String getContextPath(){
		return (String) getRequestAttribute(ContextAttributes.REQUEST_CONTEXT_PATH);
	}
	public String getContextPath(String complemento){
		return (String) getRequestAttribute(ContextAttributes.REQUEST_CONTEXT_PATH) + complemento;
	}

}
